package com.bbm.communitysystem.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bbm.communitysystem.domain.Announcement;
import com.bbm.communitysystem.domain.bo.AnnouncementBo;
import com.bbm.communitysystem.domain.dto.AnnouncementDto;
import com.bbm.communitysystem.mapper.AnnouncementMapper;
import com.bbm.communitysystem.service.IAnnouncementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bbm
 * @since 2025-02-13
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {

    private final AnnouncementMapper announcementMapper;

    @Override
    public AnnouncementDto getNewAnnouncement() {

        Announcement newAnnouncement = announcementMapper.getNewAnnouncement();
        return BeanUtil.copyProperties(newAnnouncement, AnnouncementDto.class);
    }

    @Override
    public AnnouncementDto addAnnouncement(AnnouncementBo announcementBo) {

        Announcement announcement = CreateAnnouncement(announcementBo);

        boolean save = save(announcement);

        if (!save) {
            return null;
        }


        return BeanUtil.copyProperties(announcement, AnnouncementDto.class);
    }


    public Announcement CreateAnnouncement(AnnouncementBo announcementBo) {

        Announcement announcement = new Announcement();

        announcement.setAnnTitle(announcementBo.getAnnTitle());
        announcement.setAnnContect(announcementBo.getAnnContect());
        announcement.setAnnContent(announcementBo.getAnnContent());
        announcement.setStatus(3);
        announcement.setAnnTime("----");
        announcement.setUpdateBy(announcementBo.getUpdateBy());
        announcement.setUpdateTime(System.currentTimeMillis() + "");

        return announcement;
    }


}
